package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Just、倾城
 * @created 2025-10-12
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;


    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable String type){
        List<Activity> data = activityService.listByType(type);
        return Result.success(data);
    }
    @PutMapping
    public Result update(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(){
        log.info("根据id查询");
        Activity activity = activityService.selectById();
        return Result.success(activity);
    }
    @PostMapping
    public Result add(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }
    @GetMapping
    public Result getActivityList(ActivityDTO activityDTO) {
        PageResult<Activity> data = activityService.page(activityDTO);
        return Result.success(data);
    }
}
